#include<sys/types.h>
#include<sys/socket.h>
#include<stdio.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<unistd.h>
#include<stdlib.h>
#include<pthread.h>
#include<string.h>
#include <errno.h>

int main(void)
{
    int sockfd;
    int len;
    struct sockaddr_in address;
    int result;


    address.sin_family = AF_INET;
    //注意：inet_addr函数返回的已经是按网络字节序存储的网络地址了，所以不能再加htonl了
    address.sin_addr.s_addr = inet_addr("192.168.33.205");
    address.sin_port = htons(1111);
    len = sizeof(address);

    while (1)
    {
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        result = connect(sockfd, (struct sockaddr*)&address, len);
        if (-1 == result)
        {
            perror("oops: client");
            close(sockfd);
        }
        else
        {
            printf("connect success. sockfd = %d\n", sockfd);
        }
    }

    return 0;
}
